package com.liwy3.chart;

import cn.hutool.core.util.StrUtil;
import cn.hutool.json.JSONUtil;
import com.theokanning.openai.image.CreateImageRequest;

/**
 * @author weiye.li
 * @date 2023/2/24
 */
public class SimpleImageDemo {

    private static String API_ENDPOINT = "https://api.openai.com/v1/images/generations";
    private static final String API_KEY = "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";

    public static void main(String[] args) {

        CreateImageRequest createImageRequest = CreateImageRequest.builder()
                .prompt("画一个小鸟落在一头牛的身上, 在一座大山上下着大雪, 漫画")
                .build();

        String result = YQHttp.newRequest().setUrl(API_ENDPOINT)
                .addHeader("Authorization", "Bearer " + API_KEY)
                .addHeader("Content-Type", "application/json")
                .setPostBody(StrUtil.toUnderlineCase(JSONUtil.toJsonStr(createImageRequest)))
                .setRequestConfig(YQHttp.RC_60)
                .json().getContent();
        System.out.println(result);
    }
}
